1 // Complejidad: O(E + V)
4 typedef map
<node
, vector
<node
> > graph
;
6 const color WHITE
= 0, GRAY
= 1, BLACK
= 2;
8 map
<node
, color
> colors
;
11 set
<node
> cameras
; //contendrá los puntos de articulación
14 // Uso: Para cada nodo u:
15 // colors[u] = WHITE, g[u] = Aristas salientes de u.
16 // Funciona para grafos no dirigidos.
18 void dfs(node v
, bool isRoot
= true){
20 d
[v
] = low
[v
] = ++timeCount
;
21 const vector
<node
> &neighbors
= g
[v
];
23 for (int i
=0; i
<neighbors
.size(); ++i
){
24 if (colors
[neighbors
[i
]] == WHITE
){
25 //(v, neighbors[i]) is a tree edge
26 dfs(neighbors
[i
], false);
27 if (!isRoot
&& low
[neighbors
[i
]] >= d
[v
]){
28 //current node is an articulation point
31 low
[v
] = min(low
[v
], low
[neighbors
[i
]]);
33 }else{ // (v, neighbors[i]) is a back edge
34 low
[v
] = min(low
[v
], d
[neighbors
[i
]]);
37 if (isRoot
&& count
> 1){
38 //Is root and has two neighbors in the DFS-tree